<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>login</title>
</head>
<body>
    <form id="myForm">
        用户名:<input type="text" name="username"><br>
        密码:<input type="password" name="pwd" id="pwd"><br>
        <input type="password" style="display: none" name="hpwd" id="hpwd">
        <input type="submit" value="登录">
    </form>
</body>
<script type="text/javascript" src="jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="jquery-form.js"></script>
<script type="text/javascript" src="jQuery.md5.js"></script>
<script type="text/javascript">
    $(function () {
        $('#myForm').submit(function () {
            $('#hpwd').val($.md5($('#pwd').val()));
        });
        $('#myForm').ajaxForm({
            url:"http://localhost/lr3181/login.php",
            type:'post',
            data:$('#myForm').serialize(),
            dataType:'JSON',
            success:function (data) {
                if (data['result']=='username is not exist'){
                    alert('用户名'+data['username']+'不存在');
                }else {
                    if (data['result']=='success'){
                        alert('恭喜您，登陆成功！');
                        window.location.href='http://localhost/lr3181/welcome.html';
                    }else{
                        alert('用户名或密码错误!');
                    }
                }
            },
            error:function (err) {
                console.log(err);
                alert('请求失败');
            }
            
        });
    });
</script>
</html>